var url='http://localhost:8601/';
var article_id1 = window.location.href.split("?")[1].split("=")[1];//对路径进行分割，得到？后的值
var article_url = window.location.href.split("?")[1].split("=")[2];//得到url
var article_id2 = article_id1.slice(0, article_id1.indexOf('&'));//得到文章id
var token= localStorage.getExpire("token");
$.ajax({
    xhrFields: {
        withCredentials: true
    },
    headers:{"Authorization":token},
    method: "post",
    url: url+"Article/accessArticle",
    data: {article_id: article_id2, article_url: article_url},
    dataType: "json",
    success: function (re) {
        $("#title").html(re.article_title);
//            $("#article_picture").attr("src", re.article_picture);
        $("#user_nickname").html(re.user.user_nickname);
        $("#level_name").html(re.user.userLevel.level_name);
        $("#user_userface").attr("src", re.user.user_userface);
        var yuanchuang = "background:url('images/yuanchuang.jpeg') no-repeat right 0px";
        var zhuanzai = "background: url('images/zhuanzai.png') no-repeat right 0px";
        if (re.article_original == '是') {
            $("#article_original").attr("style", yuanchuang);
        } else {
            $("#article_original").attr("style", zhuanzai);
        }
        $("#article_title").html(re.article_title);
        $("#article_publishDate").append(re.article_publishDate);
        $("#user_nickname2").html(re.user.user_nickname);
        $("#article_mdContent").html(re.article_mdContent);
        $("#article_id").attr('onclick', '').click(eval(function () {
            deleteArticle(re.article_id);
        }));
        $.each(re.commentList, function (index, item) {
            var strhtml = '';
            var str2html = '';
            strhtml += '<div class="layui-row">\n' +
                '                <div class="layui-col-md12">\n' +
                '                   <span class="coumtent"><img class="img_userface" src="'+item.users.user_userface+'"/>' + item.users.user_nickname + '</span>评论了：<span>' + item.comment_coumtent + '</span> ————删除评论<span>' + item.comment_id + '</span> ' +
                '                    <a title="删除评论" id="' + item.comment_id + '" style="padding-left: 4px;" class="layui-icon layui-icon-delete" href="javascript:" onclick="delComment(' + item.comment_id + ')"></a>\n' +
                '                </div>\n' +
                '            </div>';
            /*$("#item.comment_id").attr('onclick','').click(eval(function(){ delComment(item.comment_id); }));*/
            $.each(item.replyList, function (index, items) {
                if (item.comment_id == items.reply_articleId) {
                    str2html += '<div class="layui-row">\n' +
                        '                                <div class="layui-col-md8">\n' +
                        '                                    ' + items.users.user_nickname + '回复了' + item.users.user_nickname + '：' + items.reply_coumtent + '\n' +
                        '                                </div>\n' +
                        '                                <div class="layui-col-md2">\n' +
                        '\n' +
                        '                                </div>\n' +
                        '                                <div class="layui-col-md2">\n' +
                        '                                    删除回复' + items.reply_id +
                        '                                    <a title="删除回复" style="padding-left: 4px;" class="layui-icon layui-icon-delete" href="javascript:" onclick="delReply(' + items.reply_id + ')"></a>\n' +
                        '                                </div>\n' +
                        '                            </div>';
                }
            });
            $("#comment_coumtent").append(strhtml);
            $("#comment_coumtent").append(str2html);
        });

    }
})